package test.hello.utils;

import java.util.Calendar;
import java.util.Random;

public class StringUtils {
	
	//日期字符串 YYYY/MM/DD
	public static String getPathPrefix() {
		Calendar calendar = Calendar.getInstance();
		int day = calendar.get(Calendar.DATE);
		int month = calendar.get(Calendar.MONTH) + 1;
		int year = calendar.get(Calendar.YEAR);
		StringBuffer prefix = new StringBuffer();
		prefix.append(year).append("/").append(month).append("/").append(day).append("/");
		return prefix.toString();
	}
	
	//随机字母数字字符串
	public static String getRandomString(int length) {
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(3);
			long result = 0;
			switch (number) {
			case 0:
				result = Math.round(Math.random() * 25 + 65);
				sb.append(String.valueOf((char) result));
				break;
			case 1:
				result = Math.round(Math.random() * 25 + 97);
				sb.append(String.valueOf((char) result));
				break;
			case 2:
				sb.append(String.valueOf(new Random().nextInt(10)));
				break;
			}
		}
		return sb.toString();
	}
	
	//字符串str2 是不是str1的子串
	public boolean contains(String str1,String str2) {
		return str1.contains(str2);
	}

}
